import {
  IPermissionConfig,
  PermissionType
} from "@/model/frame/IPermissionConfig";
import { IViewItem } from "@/model/frame/IViewItem";
import { ViewItems } from "@/model/frame/ViewItems";

const PermissionConfigs: IPermissionConfig[] = [];

function genPermission(item: IViewItem) {
  if (item.items) {
    PermissionConfigs.push({
      name: item.name,
      type: PermissionType.DIR
    });

    item.items.forEach(genPermission);
  } else {
    PermissionConfigs.push({
      name: item.name,
      type: PermissionType.ROUTE
    });
  }
}

ViewItems.instance().groups.forEach(genPermission);

export default PermissionConfigs;
